<!DOCTYPE html>
<html>
<head>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"/>
    <meta charset="UTF-8">
    <title>固件添加</title>
    {% include 'template/baseCss.volt' %}
    <link href="/css/vendor/add-drone.less" rel="stylesheet/less" type="text/css">
    <script src="/js/less.min.js"></script>
</head>
<body>
<main>
    <form>
        <div class="title-bar">
            <label class="server-id">固件信息编辑</label>
        </div>
        <div id="info-wrap">
            <table>
                <tr>
                    <th>固件分类: </th>
                    <td>
                        <select id="firmware_type_id">
                            <option value="">请选择</option>
                            {% for id,name in firmwareTypeList %}
                                <option value="{{ id }}" {% if data["firmware_type_id"] == id %}selected{% endif %}>{{ name }}</option>
                            {% endfor %}
                        </select>
                        <label id="add-type-btn" style="cursor:pointer; font-size: 1.5rem; color: #009bff">添加分类</label>
                    </td>
                </tr>
                <tr>
                    <th>固件名称: </th>
                    <td>
                        <input type="text" id="name" value={{ data["name"] }}>
                    </td>
                </tr>
                <tr>
                    <th>版本号: </th>
                    <td>
                        <input type="text" id="version" value={{ data["version"] }}>

                    </td>
                </tr>
                <tr>
                    <th>下载链接:</th>
                    <td>
                        <input type="text" id="url" value={{ data["url"] }}>
                    </td>
                </tr>
                <tr>
                    <th>版本说明:</th>
                    <td>
                        {#<div class="version-content" id="content"><?php echo $data["html"]?></div>#}
                    </td>
                </tr>
            </table>
            <div class="version-content" id="content"><?php echo $data["html"]?></div>
        </div>
        <p id="save-btn" class="button" style="visibility: visible">保存</p>
        <p id="reset-btn" class="button" style="visibility: visible">重置</p>
    </form>
    <div class="list-box" style="display: none">
        <div class="box-title">
            <label>添加分类</label>
            {#<label class="close-btn">close</label>#}
            <img src="/images/info_edit_del.png" class="close-btn">
        </div>
        <div class="box-list">
            <table class="box-table" cellpadding="0" cellspacing="0">

            </table>
        </div>
        <div class="box-bottom-btn">
            <p class="button" onclick="listBox.clickBoxAdd(this)">添加</p>
            <p class="button" onclick="listBox.clickBoxDel()">删除</p>
        </div>
    </div>
</main>
</body>

{% include 'template/baseJs.volt' %}
<script type="text/javascript" src="/third-part/wang-editor/wangEditor.min.js"></script>
<script src="/js/cos-js-sdk-v5.js"></script>
<script src="/js/vendor/upload-cos.js"></script>

<script>

    var editor = undefined;
    var id = getQueryString("id");

    $(function () {
        var E = window.wangEditor;
        editor = new E('#content');
        editor.customConfig.zIndex = 100;
        editor.create();
        CosUpload.cosInit("/file/getCosInfo");
    });

    $("#reset-btn").click(function (){
        location.reload();
    });

    $("#save-btn").click(function () {
        var data = {
            "action_key": REQUEST_ACTION_UPDATE,
            "id": id,
            "name": $("#name").val(),
            "version": $("#version").val(),
            "firmware_type_id": $("#firmware_type_id").val(),
            "url": $("#url").val(),
            "html": editor.txt.html()
        };
        feimaPost("/firmware/detailFirmwareVersion", data, function (result) {
            if (result.status == 0) {
                window.location.href = "/firmware/listFirmwareVersion";
            } else {
                FAlert(result.message);
            }
        });
    });

    $("#add-type-btn").click(function () {
        $(".list-box").css("display", "block");
        listBox.config = {
            "head": {"id": "ID", "name":"分类名称"},
            "colwidth": {"id": "100", "name": "250"},
            "url": "/firmware/listFirmwareType"
        };
        listBox.init();
    });
    $(".close-btn").click(function () {
        $(".list-box").css("display", "none");
        window.location.href = "/firmware/detailFirmwareVersion?id=" + id;
    });

</script>
</html>